package com.example.administrator.xtu_community.activity;

import android.content.Intent;
import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.example.administrator.xtu_community.R;
import com.google.android.material.appbar.CollapsingToolbarLayout;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.appcompat.widget.Toolbar;
import androidx.navigation.ui.AppBarConfiguration;

public class InforActivity extends AppCompatActivity {

    private AppBarConfiguration appBarConfiguration;

    public static final String INFOR_NAME = "infor_name";
    public static final String INFOR_IMAGE_ID = "infor_image_id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infor);
        Intent intent = getIntent();
        String inforName = intent.getStringExtra(INFOR_NAME);
        int inforImaged = intent.getIntExtra(INFOR_IMAGE_ID,0);
        Toolbar toolbar = (Toolbar) findViewById(R.id.infor_toolbar);
        CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.infor_collapsing_toolbar);
        ImageView inforImageView = (ImageView) findViewById(R.id.infor_background_view);
        TextView inforContentText = (TextView) findViewById(R.id.infor_content_text);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        collapsingToolbar.setTitle(inforName);
        Glide.with(this).load(inforImaged).into(inforImageView);
        String inforContent = generateInforContent(inforName);
        inforContentText.setText(inforContent);

    }

    private String generateInforContent(String inforName){
        StringBuilder inforContent = new StringBuilder();
        inforContent.append(inforName);
        return inforContent.toString();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}